// pages/travel_infoPage/travel_infoPage.js
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    contentList: [{
      'id': '0'
    }, {
      'id': '1'
    }, {
      'id': '1'
    }, {
      'id': '0'
    }, {
      'id': '1'
    }, {
      'id': '0'
    }, {
      'id': '1'
    }],
    isHidden:true,
    allTimeList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this;
    var bannerList = [];
    var timeList = []
    for (var i = 0; i < 20; i++) {
      bannerList.push({
        'pic': '../imagesource/banner6.png'
      })
      timeList.push({ 'title':'11-06 周二','money':'¥2100','ismore':false})
    }
    that.setData({
      bannerList: bannerList,
      timeList: timeList,
      allTimeList:timeList
    })
    that.getTheTimeList()
  },
  //弹出提示电话
  showPhonenumber: function () {
    var phonelist = ['18941153507', '18640909666'];
    wx.showActionSheet({
      itemList: phonelist,
      success(res) {
        console.log(res);
        wx.makePhoneCall({
          phoneNumber: phonelist[res.tapIndex],
        })
      }
    })
  },

  //点击更多事件
  touchevent:function(){
    console.log('touch')
    that.setData({
      isHidden: !that.data.isHidden
    })
    that.getTheTimeList()
  },
  //判断显示数量
  getTheTimeList:function(){
    if (that.data.allTimeList.length<=8){
      that.setData({
        timeList: that.data.allTimeList
      })
      
    }else{
      var newTimeList=[];
      if(that.data.isHidden){
        for(var i=0;i<7;i++){
          if (!that.data.allTimeList[i].ismore) {
            newTimeList.push(that.data.allTimeList[i]);
          }
        }
        newTimeList.push({ 'title': '更多...',  'ismore': true })
        that.setData({
          timeList:newTimeList
        })
      }else{
        for (var i = 0; i < that.data.allTimeList.length; i++) {
          if(!that.data.allTimeList[i].ismore){
            newTimeList.push(that.data.allTimeList[i]);
          }
        }
        newTimeList.push({ 'title': '收起', 'ismore': true })
        that.setData({
          timeList: newTimeList
        })
      }
    }
  }

})